<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="CommonUtil/CommonUtil.js"></script>
    <script type="text/javascript" charset="utf-8">
        var Org = function (name) {
            this.name = name;
            this.depts = [];
        }
        Org.prototype = {
            constuctor:Org,
            addDept:function (child) {
                this.depts.push(child);
                return this;
            },
            getDepts:function () {
                return this.depts;
            }
        }
        var Dept = function (name) {
            this.name = name;
            this.persons = [];
        }
        Dept.prototype = {
            constructor:Dept,
            addPerson:function (child) {
                this.persons.push(child);
                return this;
            },
            getPersons:function () {
                return this.persons;
            }
        }
        var Person = function (name) {
            this.name = name;
        }
        Person.prototype = {
            constructor:Person,
            hardWorking:function () {
                document.write(this.name+'...努力工作...');
            },
            sleeping:function () {
                document.write(this.name+'...努力睡觉...');
            }
        }
        var p1 = new Person('zhang1');
        var p2 = new Person('zhang2');
        var p3 = new Person('zhang3');
        var p4 = new Person('zhang4');
        var p5 = new Person('zhang5');
        var p6 = new Person('zhang6');
        var d1 = new Dept('开发部门');
        d1.addPerson(p1).addPerson(p2).addPerson(p3);
        var d2 = new Dept('销售部门');
        d2.addPerson(p4).addPerson(p5).addPerson(p6);
        var org = new Org('中软国际');
        org.addDept(d1).addDept(d2);
        /**
         * 具体让一个人去努力工作
         */
        for(var i = 0,depts = org.getDepts();i<depts.length;i++){
            var dept=depts[i];
            for(var j = 0,persons = dept.getPersons();j<persons.length;j++){
               if(persons[j].name==='zhang3'){
                   persons[j].hardWorking();
               }
            }
        }
    </script>
</head>
<body>
</body>
</html>